<?php
namespace Application\Repository;
use Doctrine\ORM\EntityRepository;

class CommentRepository extends AbstractRepository
{
    protected  $entity="Application\\Entity\\Comment";

    public function getByNextCommentId($nextCommentId,$number = 30)
    {
    	$dql = "SELECT c FROM $this->entity c WHERE c.next_comment_id=?1";
    
    	return $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $nextCommentId)
    	->setMaxResults($number)
    	->getResult();
    }
    
    public function getByPreviousCommentId($previousCommentId,$number = 30)
    {
    	$dql = "SELECT c FROM $this->entity c WHERE c.previous_comment_id=?1";
    
    	return $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $previousCommentId)
    	->setMaxResults($number)
    	->getResult();
    }
    
    public function getByResponseCommentId($responseCommentId,$number = 30)
    {
    	//$dql = "SELECT c FROM $this->entity c WHERE c.response_comment_id=?1";
    	$dql = "SELECT c FROM $this->entity c JOIN c.responseComment r WHERE r.id=?1";
    
    	return $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $responseCommentId)
    	->setMaxResults($number)
    	->getResult();
    }
}